<?php

namespace App\Models\Api;

class Favorite extends ApiModel
{
    //表名
    protected $table = 'favorites';

    protected $guarded = [];

    protected $hidden = ['com_id', 'company_job', 'company_basic'];

    public function company_basic()
    {
        return $this->hasOne(CompanyBasic::class, 'id', 'com_id')->select('id', 'company_name', 'logo');
    }

    public function getCompanyNameAttribute()
    {
        return $this->company_basic ? $this->company_basic->company_name : '';
    }

    public function company_job()
    {
        return $this->hasOne(CompanyJob::class, 'id', 'job_id')
            ->select('id', 'job_title', 'location1', 'location2', 'location3', 'location4',
                'location5', 'education', 'work_year', 'salary_above', 'salary_below', 'updatetime',
                'urgent', 'part_status');
    }

    public function getJobTitleAttribute()
    {
        return $this->company_job ? $this->company_job->job_title : '';
    }

    public function getLocationNameAttribute()
    {
        return $this->company_job ? $this->company_job->location_name : '';
    }

    public function getEducationNameAttribute()
    {
        return $this->company_job ? $this->company_job->education_name : '';
    }

    public function getWorkYearNameAttribute()
    {
        return $this->company_job ? $this->company_job->work_year_name : '';
    }

    public function getSalaryAttribute()
    {
        return $this->company_job ? $this->company_job->salary : '';
    }

    public function getIsUrgentAttribute()
    {
        return $this->company_job ? $this->company_job->is_urgent : '';
    }

    public function getUpdatetimeAttribute()
    {
        return $this->company_job ? $this->company_job->updatetime : '';
    }

    public function getPartStatusAttribute()
    {
        return $this->company_job ? $this->company_job->part_status : '';
    }

}
